<?php
namespace Home\Controller;

use Think\Controller;

class CommonController extends Controller
{
  protected $user_id;
  protected $shop_id;
  protected $types;
  protected $current_time;
  protected $app_id;
  protected $app_info;

  public function __construct()
  {
    parent::__construct();

    $this->current_time = gmtime();
  }

  //验证登陆
  public function check_login()
  {
    $header = get_all_headers();

    if ($header['token']) {
      $user = D("Users")->check_token($header['token']);
      if ($user) {
        $this->user_id = $user['user_id'];
        $this->app_id = $user['app_id'];
        $this->shop_id = $user['types'] == 1 ? $user['shop_id'] : 0;
        //TODO:判断shop_id是不是就可以了？
        $this->types = $user['types'];
        $this->app_id = $user['app_id'];
        $this->app_info = M('apps')->where("id={$user['app_id']}")->find();

        return $user;
      }
    } else {
      return_data("error", "header.token.blank");
    }

    return_data("error", "header.token.error");
  }
  public function shops_close()
  {
      if($this->shop_id && M("Shops")->where("id=$this->shop_id AND status=2")->find()){
        return_data("error", "shop_id.close.blank");
      }
  }
}
